package com.neperia.migratore;

import java.util.ArrayList;

public class Table {

	public String db;
	public String name;
	public int length;
	public Key[] key;
	public boolean isRoot;

	public Table(String name, int length, String db){
		this.db=db;
		this.name=name;
		this.length=length;

	}

	public String getName(){
		return this.name;
	}
	public int getLength(){
		return this.length;
	}

	public void setName(String name){
		this.name=name;
	}
	public void setLength(int length){
		this.length=length;
	}

	public Key[] getKeys(){
		return this.key;
	}
	public void setKey(Key[] key){
		this.key=key;
	}
	public Key getKey(int n){
		return this.key[n];
	}

	public Parent[] getSons(DataBase r, String nome_padre){

		ArrayList<Parent> sons = new ArrayList<Parent>();

		for(int i=0;i<r.tab.length;i++){
			for(int k=0;k<r.tab[i].key.length;k++){
				if(r.tab[i].key[k].parent!=null){
					if(r.tab[i].key[k].parent[0].equals(nome_padre)){
						//sons.add());//TODO get SOns
						Parent p = new Parent(r.tab[i].name, r.tab[i].length, r.tab[i].key[k].name,
								r.tab[i].key[k].offset,r.tab[i].key[k].len_chiave,r.tab[i].key[k].type,
								r.tab[i].key[k].unique, r.tab[i].key[k].len_campo);
						sons.add(p);
					}
				}
				
			}
			

		}
		//System.out.print("Padre: "+nome_padre+" - ");
		Parent[] s = null;
		if(sons.size()>0){
			s = new Parent[sons.size()];
			for(int i=0;i<sons.size();i++){
				s[i]=sons.get(i);
				//System.out.print(s[i].nome_parent+", ");
			}
		}
		//System.out.println("!");
		return s;

	}

}
